<template>
  <div class="dashboard-editor-container">
    <panel-group :data="panelChartData" @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="lineChartData" />
    </el-row>

    <el-row>
      <user-buy-chart />
    </el-row>

    <el-row :gutter="32" style="margin-top: 20px">
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart :chartdata="pieData" />
        </div>
      </el-col>
      <el-col :xs="48" :sm="48" :lg="16">
        <div class="chart-wrapper">
          <bar-chart :chartdata="lineData" />
        </div>
      </el-col>
    </el-row>


    <el-row>
      <selector-search />
    </el-row>

  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import UserBuyChart from '@/views/dashboard/admin/components/UserBuyChart'
import SelectorSearch from '@/views/dashboard2/admin/components/SelectorSearch'
import axios from 'axios'

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart,
    PieChart,
    BarChart,
    SelectorSearch,
    UserBuyChart
  },
  data() {
    return {
      panelChartData: null,
      lineChartData: null,
      lineData: null,
      chartName: null,
      pieData: null
    }
  },
  mounted() {
    this.accessPanelAndLineData()
    this.accessTopPie()
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = this.lineData[type]
    },
    accessPanelAndLineData() {
      axios.get('http://127.0.0.1:8000/all/get_all_count').then((response) => {
        const data = response.data
        this.panelChartData = data['panel']
        this.lineData = data['line']
        this.lineChartData = this.lineData.pv
      }).catch(err => {
        console.log(err)
      })
    },
    accessTopPie() {
      axios.get('http://127.0.0.1:8000/all/get_pie_info').then(response => {
        const data = response.data
        this.pieData = data.data
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
